<template>
  <a-config-provider>
    <router-view v-if="isRouterAlive" />
    <global-setting />
  </a-config-provider>
</template>

<script lang="ts" setup>
  import { ref, nextTick, provide, onUnmounted } from 'vue';
  // import enUS from '@arco-design/web-vue/es/locale/lang/en-us';
  // import zhCN from '@arco-design/web-vue/es/locale/lang/zh-cn';
  import GlobalSetting from '@/components/global-setting/index.vue';
  import { useRouterStore } from './store';
  // 清除缓存
  onUnmounted(() => {
    localStorage.clear();
  });

  const RouterStore = useRouterStore();
  // import useLocale from '@/hooks/locale';

  // const { currentLocale } = useLocale();
  // const locale = computed(() => {
  //   switch (currentLocale.value) {
  //     case 'zh-CN':
  //       return zhCN;
  //     case 'en-US':
  //       return enUS;
  //     default:
  //       return enUS;
  //   }
  // });
  // 创建完毕状态
  //在页面加载时读取sessionStorage里的状态信息
  // if (sessionStorage.getItem('store')) {
  //   RouterStore.routes.replaceState(
  //     Object.assign(
  //       {},
  //       this.$store.state,
  //       JSON.parse(sessionStorage.getItem('store'))
  //     )
  //   );
  // }
  //在页面刷新时将vuex里的信息保存到sessionStorage里
  // window.addEventListener('beforeunload', () => {
  //   sessionStorage.removeItem('DynamicRoute');
  //   sessionStorage.setItem(
  //     'DynamicRoute',
  //     JSON.stringify(RouterStore.aRouterList)
  //   );
  // });
  // sessionStorage.setItem(
  //   'DynamicRoute',
  //   JSON.stringify(RouterStore.aRouterList)
  // );
  // 局部组件刷新
  const isRouterAlive = ref(true);
  const reload = () => {
    isRouterAlive.value = false;
    nextTick(() => {
      isRouterAlive.value = true;
    });
  };
  provide('reload', reload);
</script>
